package game;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class Screen extends JFrame {
	private JLabel[][] labels;

	private String[][] level;

	/**
	 * 
	 * @param level
	 * @param posX
	 * @param posY
	 */
	public Screen(String[][] level) {
		super("TKgame v. 1.0");
		this.level = level;
		labels = new JLabel[level.length][level.length];

		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setLocation(100, 100);
		this.setSize(500, 500);
		this.setResizable(true);
		this.setLayout(new GridLayout(20, 20, 0, 0));
		draw();
		this.setAlwaysOnTop(false);
		this.repaint();
		this.setVisible(true);

	}

	/**
	 * 
	 * @param oldX
	 * @param oldY
	 * @param x
	 * @param y
	 * @param playerDirection
	 */
	public void movePlayerOnScreen(int oldX, int oldY, int x, int y,
			String playerDirection) {

		labels[oldX][oldY].setIcon(ImageLoader.loadImage("img/gulv2.png"));

		if (playerDirection.equals("right")) {
			labels[x][y].setIcon(ImageLoader.loadImage("img/heltHoejre.png"));
		}

		if (playerDirection.equals("left")) {
			labels[x][y].setIcon(ImageLoader.loadImage("img/heltVenstre.png"));
		}

		if (playerDirection.equals("up")) {
			labels[x][y].setIcon(ImageLoader.loadImage("img/heltOp.png"));
		}

		if (playerDirection.equals("down")) {
			labels[x][y].setIcon(ImageLoader.loadImage("img/heltNed.png"));
		}
	}
	
	/**
	 * 
	 * @param posX
	 * @param posY
	 * 
	 */
	public void addHero(int posX, int posY){
		labels[posX][posY].setIcon(ImageLoader.loadImage("img/heltOp.png"));
	}


	public void draw() {
		for (int j = 0; j < level.length; j++) {
			for (int i = 0; i < level[j].length; i++) {
				if (level[i][j].equalsIgnoreCase("w")) {
					// wall
					JLabel l = new JLabel(ImageLoader.loadImage("img/mur1.png"));
					l.setSize(50, 50);
					this.add(l);
					labels[i][j] = l;
				} else if (level[i][j].equalsIgnoreCase("e")) {
					// empty
					JLabel l = new JLabel(ImageLoader.loadImage("img/gulv2.png"));
					l.setSize(50, 50);
					this.add(l);
					labels[i][j] = l;
				}
			}
		}
	}
}
